import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class L77 {
    public static void main(String[] args) {
        List<List<Integer>> combine = new Solution().combine(4, 2);
        for (List<Integer> integers : combine) {
            System.out.println(integers.toString());
        }

    }


    static class Solution {
        List<List<Integer>> result = new ArrayList<>();
        LinkedList<Integer> node = new LinkedList<>();

        public List<List<Integer>> combine(int n, int k) {
            int index = 1;
            backTracking(n, k, index);
            return result;

        }

        private void backTracking(int n, int k, int index) {

            if (node.size() == k) {
                result.add(new LinkedList<>(node));
                return;
            }

            for (int i = index; i <= n - k + node.size() + 1; i++) {
                node.add(i);
                backTracking(n, k, i + 1);
                node.removeLast();
            }
        }
    }
}
